package com.testdocs.client.signin.context;

import com.google.gwt.event.shared.EventBus;
import com.testdocs.client.signin.event.SignInEvent;
import com.testdocs.client.signin.event.SignInEventHandler;
import com.testdocs.client.signin.event.SignOutEvent;
import com.testdocs.client.signin.event.SignOutEventHandler;

public class SignInContextHolder {
	private boolean signedIn = false;
	
	public SignInContextHolder(EventBus eventBus) {
		eventBus.addHandler(SignInEvent.TYPE, new SignInHandler());
		eventBus.addHandler(SignOutEvent.TYPE, new SignOutHandler());
	}

	public boolean isSignedIn() {
		return signedIn;
	}

	public void setSignedIn(boolean signedIn) {
		this.signedIn = signedIn;
	}
	
	
	public class SignInHandler implements SignInEventHandler {
		@Override
		public void signedIn(SignInEvent signInEvent) {
			setSignedIn(true);
		}
	}

	public class SignOutHandler implements SignOutEventHandler {
		@Override
		public void signedOut(SignOutEvent signOutEvent) {
			setSignedIn(false);
		}
	}
}
